package com.hospital.doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.doctor.domain.ReserveInfo;
import com.hospital.doctor.domain.vo.ReserveInfoVo;
import com.hospital.doctor.mapper.EltReserveMapper;
import com.hospital.doctor.service.EltReserveService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：zhuzhujiang
 * @Description:
 * @name：EltReserveServiceImpl
 * @Date：2024/10/17 17:26
 */
@Service
public class EltReserveServiceImpl extends ServiceImpl<EltReserveMapper, ReserveInfo> implements EltReserveService {


    @Override
    public void setReverseCount(ReserveInfoVo rserveInfoVo) {

        List<ReserveInfo> list = new ArrayList<>();
        rserveInfoVo.getDates().forEach(date -> {

            //在设置前需要判断该医生是否已经在当前日期有预约了
            ReserveInfo reserveInfo = new ReserveInfo();
            reserveInfo.setDoctorId(rserveInfoVo.getDoctorId());
            reserveInfo.setReserveDate(date);
            reserveInfo.setReverseNum(rserveInfoVo.getReserveNum());
            reserveInfo.setDepartmentId(rserveInfoVo.getDepartmentId());
            list.add(reserveInfo);
        });
        this.saveBatch(list);

    }

    @Override
    public List<ReserveInfo> getReserveDate(Long doctorId, Long departmentId) {


        List<ReserveInfo> list = this.list(new QueryWrapper<ReserveInfo>()
                .lambda()
                .eq(ReserveInfo::getDoctorId, doctorId)
                .eq(ReserveInfo::getDepartmentId, departmentId));

        return list;
    }
}

